/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package pt.iasd.youthshelter.datamodel;

import java.io.Serializable;
import java.sql.Blob;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Rui
 */
@Entity
@Table(name = "PATHFINDER")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Pathfinder.findAll", query = "SELECT p FROM Pathfinder p"),
    @NamedQuery(name = "Pathfinder.findById", query = "SELECT p FROM Pathfinder p WHERE p.id = :id"),
    @NamedQuery(name = "Pathfinder.findByName", query = "SELECT p FROM Pathfinder p WHERE p.name = :name"),
    @NamedQuery(name = "Pathfinder.findByIdCard", query = "SELECT p FROM Pathfinder p WHERE p.idCard = :idCard"),
    @NamedQuery(name = "Pathfinder.findByPhoneNumber", query = "SELECT p FROM Pathfinder p WHERE p.phoneNumber = :phoneNumber"),
    @NamedQuery(name = "Pathfinder.findByCellphoneNumber", query = "SELECT p FROM Pathfinder p WHERE p.cellphoneNumber = :cellphoneNumber"),
    @NamedQuery(name = "Pathfinder.findByEmail", query = "SELECT p FROM Pathfinder p WHERE p.email = :email"),
    @NamedQuery(name = "Pathfinder.findByStartActive", query = "SELECT p FROM Pathfinder p WHERE p.startActive = :startActive"),
    @NamedQuery(name = "Pathfinder.findByEndActive", query = "SELECT p FROM Pathfinder p WHERE p.endActive = :endActive")})
public class Pathfinder implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID")
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 200)
    @Column(name = "NAME")
    private String name;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 15)
    @Column(name = "ID_CARD")
    private String idCard;
    @Column(name = "PHONE_NUMBER")
    private Integer phoneNumber;
    @Column(name = "CELLPHONE_NUMBER")
    private Integer cellphoneNumber;
    // @Pattern(regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", message="Invalid email")//if the field contains email address consider using this annotation to enforce field validation
    @Size(max = 50)
    @Column(name = "EMAIL")
    private String email;
    @Basic(optional = false)
    @NotNull
    @Column(name = "START_ACTIVE")
    @Temporal(TemporalType.DATE)
    private Date startActive;
    @Column(name = "END_ACTIVE")
    @Temporal(TemporalType.DATE)
    private Date endActive;
    @Lob
    @Column(name = "PHOTO")
    private Blob photo;
    @JoinTable(name = "SCHOOL_PARTICIPATION", joinColumns = {
        @JoinColumn(name = "PATHFINDER_ID", referencedColumnName = "ID")}, inverseJoinColumns = {
        @JoinColumn(name = "GRADUATION_ID", referencedColumnName = "ID")})
    @ManyToMany
    private List<GraduationSchool> graduationSchoolList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "pathfinderId")
    private List<PathfinderRole> pathfinderRoleList;
    @JoinColumn(name = "CHURCH_ID", referencedColumnName = "ID")
    @ManyToOne(optional = false)
    private Church churchId;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "pathfinderId")
    private List<Investiture> investitureList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "pathfinder")
    private List<ActivityParticipation> activityParticipationList;

    public Pathfinder() {
    }

    public Pathfinder(Integer id) {
        this.id = id;
    }

    public Pathfinder(Integer id, String name, String idCard, Date startActive) {
        this.id = id;
        this.name = name;
        this.idCard = idCard;
        this.startActive = startActive;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getIdCard() {
        return idCard;
    }

    public void setIdCard(String idCard) {
        this.idCard = idCard;
    }

    public Integer getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(Integer phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public Integer getCellphoneNumber() {
        return cellphoneNumber;
    }

    public void setCellphoneNumber(Integer cellphoneNumber) {
        this.cellphoneNumber = cellphoneNumber;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Date getStartActive() {
        return startActive;
    }

    public void setStartActive(Date startActive) {
        this.startActive = startActive;
    }

    public Date getEndActive() {
        return endActive;
    }

    public void setEndActive(Date endActive) {
        this.endActive = endActive;
    }

    public Blob getPhoto() {
        return photo;
    }

    public void setPhoto(Blob photo) {
        this.photo = photo;
    }

    @XmlTransient
    public List<GraduationSchool> getGraduationSchoolList() {
        return graduationSchoolList;
    }

    public void setGraduationSchoolList(List<GraduationSchool> graduationSchoolList) {
        this.graduationSchoolList = graduationSchoolList;
    }

    @XmlTransient
    public List<PathfinderRole> getPathfinderRoleList() {
        return pathfinderRoleList;
    }

    public void setPathfinderRoleList(List<PathfinderRole> pathfinderRoleList) {
        this.pathfinderRoleList = pathfinderRoleList;
    }

    public Church getChurchId() {
        return churchId;
    }

    public void setChurchId(Church churchId) {
        this.churchId = churchId;
    }

    @XmlTransient
    public List<Investiture> getInvestitureList() {
        return investitureList;
    }

    public void setInvestitureList(List<Investiture> investitureList) {
        this.investitureList = investitureList;
    }

    @XmlTransient
    public List<ActivityParticipation> getActivityParticipationList() {
        return activityParticipationList;
    }

    public void setActivityParticipationList(List<ActivityParticipation> activityParticipationList) {
        this.activityParticipationList = activityParticipationList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Pathfinder)) {
            return false;
        }
        Pathfinder other = (Pathfinder) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "pt.iasd.youthshelter.datamodel.Pathfinder[ id=" + id + " ]";
    }
    
}
